<?php
class Module_Edit {
	/*
	 * 更新表
	 */
	public function update($tablename,$row,$where){
		$sql = 'update '.$tablename.' set ';
		$where = ' where 1=1 and '.$where;
		foreach($row as $k=>$v){
			$set .= '`'.$k.'`=\''.$v.'\',';
		}
		$set = trim($set,',');
		$sql = $sql.$set.$where;
		
		return mysql_query($sql);
	}
	
	/*
	 * 插入表
	 * $row = array('id'=>1,'grade'=>'2') 键值对应数据表属性
	 */
	public function insert($tablename,$row){
		foreach ($row as $k=>$v){
			$keys .= '`'.$k.'`,';
			$values .= '\''.$v.'\',';
		}
		$keys = rtrim($keys,',');
		$values = rtrim($values,',');
		$sql = 'insert into '.$tablename.'('.$keys.') values('.$values.')';
		
		return mysql_query($sql);
	}
	public function delete($table,$where){
		$sql = "delete from ".$table.' where '.$where;
		return mysql_query($sql);
	}
	/*
	 * 删除表
	 */
	public function deleteMod($id){
		$sql = 'delete from `zjx_module_admin` where 1=1 and `z_id`='.$id;
		return mysql_query($sql);
	}
}